package com.zs.grain.ui

import android.os.Bundle
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.jeremyliao.liveeventbus.LiveEventBus
import com.zs.grain.*
import com.zs.grain.databinding.*
import com.xnkj1688.semplibrary.mvvm.*

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
@Route(path = ARouterPath.DeployFragment)
class DeployFragment : BaseMvvmFragment<FragmentDeployBinding, DeployViewModel>() {

    override val layoutId = R.layout.fragment_deploy

    override fun initViewModel(binding: FragmentDeployBinding) {
        binding.vm = this.mViewModel
        binding.view = this
    }

    override fun initCreate() {
        LiveEventBus.get("Deploy", Long::class.java).observe(this, Observer {
            mViewModel.init(it)
        })
    }

    override fun initArguments() {
        var menuNo = this.arguments?.getLong("MenuNo")
        if (menuNo != null) mViewModel.init(menuNo)
    }

    override fun onUiNotify(name: String, bundle: Bundle) {
        when(name){
            "Timeout" -> {
                mViewModel.stopCheckDeployTimer()
                var bundle = Bundle()
                bundle.putString("UI", "Menus")
                LiveEventBus.get("SwitchUI").post(bundle)
            }
        }
        super.onUiNotify(name, bundle)
    }

    override fun onPause() {
        super.onPause()
        this.mViewModel.mSoundService.stopSound2()
    }
}
